/**
 * Created by Administrator on 2019/5/18/018.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"
import SMAP_LinkedList from "./../utils/SMAP_LinkedList.js"

class CZML_OrbitAltitudeLine {
    constructor(viewer, id, DataStartTimeStartPos, DataStartTimeEndPos, StartPos, StartPosType, relSecs, LineWidth, LineColor, LineStyle, MarkerVisible, ReferenceFrame) {
        this._viewer = viewer
        this.id = id
        this.DataStartTimeStartPos = DataStartTimeStartPos
        this.DataStartTimeEndPos = DataStartTimeEndPos
        this.StartPos = StartPos
        this.StartPosType = StartPosType
        this.relSecs = relSecs
        this.LineWidth = LineWidth
        this.LineColor = LineColor
        this.LineStyle = LineStyle
        this.MarkerVisible = MarkerVisible
        this.ReferenceFrame = ReferenceFrame
        this.posAid = id + "-to-posA"
        this.posBid = id + "-to-posB"
        this.CZML_AddOrbitAltitudeLine()
    }

    CZML_AddOrbitAltitudeLine() {
        let StartPoint2
        // UTCG时间格式转换
        const sDataStartTimeStartPos = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.DataStartTimeStartPos)
        const sDataStartTimeEndPos = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.DataStartTimeEndPos)

        if (this.StartPosType === 1) {
            const StartPoint1 = CZML_GENERALTOOLS_CLASS.FindModelObjectInformation(this.StartPos, this.relSecs)
            StartPoint2 = CZML_GENERALTOOLS_CLASS.CartesianToGeodeticCoordinateTransformation(StartPoint1)
        }
        if (this.StartPosType === 2) {
            StartPoint2 = this.StartPos
        }
        const positionA = [StartPoint2[0], StartPoint2[1], 0]
        // posA地下的点；posB顶上的点
        const posA = {
            id: this.posAid,
            name: this.posAid,
            availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
            show: true,
            position: {
                interpolationAlgorithm: "LAGRANGE",
                interpolationDegree: 5,
                referenceFrame: this.ReferenceFrame,
                epoch: sDataStartTimeStartPos,
                cartographicDegrees: positionA
            }
        }
        // 插入该数据对象
      CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posAid, posA, true)
      const posAid = this.posAid
      const FindNode = CZML_GENERALTOOLS_CLASS.CzmlList.find(function (node) {
            return node.data().id === posAid
        })
        const heightlabel = "Height:" + Math.ceil(StartPoint2[2]) + "metres"
        const posB = {
            id: this.posBid,
            name: this.posBid,
            availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
            show: true,
            label: {
                fillColor: {
                    rgba: this.LineColor
                },
                font: "11pt Lucida Console",
                horizontalOrigin: "CENTER",
                pixelOffset: {
                    cartesian2: [
                        30, 10
                    ]
                },
                show: this.MarkerVisible,
                style: "FILL_AND_OUTLINE",
                text: heightlabel,
                verticalOrigin: "CENTER"
            },
            position: {
                interpolationAlgorithm: "LAGRANGE",
                interpolationDegree: 5,
                referenceFrame: this.ReferenceFrame,
                epoch: sDataStartTimeEndPos,
                cartographicDegrees: StartPoint2
            }
        }
        // 插入该数据对象
        const ret1 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posAid, posA, true)
        const ret2 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posBid, posB, true)
        const PosARef = this.posAid + "#position"
        const PosBRef = this.posBid + "#position"

        const Line = {
            id: this.id,
            name: this.id,
            availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
            polyline: {
                show: [
                    {
                        interval: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
                        boolean: true
                    }
                ],
                width: this.LineWidth,
                material: {
                    solidColor: {
                        color: {
                            rgba: this.LineColor
                        }
                    }
                },
                followSurface: false,
                positions: {
                    references: [
                        PosARef, PosBRef
                    ]
                }
            }
        }
        if (this.LineStyle === 1) {
            Line.polyline.material = {
                polylineDash: {
                    color: {
                        rgba: this.LineColor
                    }
                }
            }
        }
        // 箭头
        if (this.LineStyle === 2) {
            Line.polyline.material = {
                polylineArrow: {
                    color: {
                        rgba: this.LineColor
                    }
                }
            }
        }
        // 插入该数据对象
        const ret3 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, Line, true)
        // 上图
        CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
        return ret1 && ret2 && ret3
    }
}
export default CZML_OrbitAltitudeLine
